<template>
  <div :class="`super-chat${otherClass}`" :title="data['time']">
    <div class="header">
      <div class="image">
        <img alt="Avatar" :src="data['avatar']" class="avatar"/>
        <div class="mask"/>
      </div>
      <span class="name" :style="`color: ${data['nameColor']}`">{{ data['username'] }}</span>
      <span v-for="item in data['identities']" :class="`identity identity_${item}`"></span>
      <div style="flex: 1"></div>
      <span class="fee">{{ '￥' + data['bounty'] }}</span>
    </div>
    <div v-if="!!data['content']" class="content" :style="`color: ${data['contentColor']}`">{{ msg }}</div>
    <div class="mask"></div>
  </div>
</template>

<script setup>
import {computed, inject} from 'vue'

const props = defineProps({
  data: {
    type: Object,
    default: {}
  }
})
const config = inject('config')
const otherClass = computed(() => {
  let result = ''
  for (let identity of props.data['identities'])
    result += ' super-chat_' + identity
  return result
})
const msg = computed(() => {
  let result = props.data['content']
  for(let item of config.shield.Keyword) {
    let length = item.length
    let stars = ''
    for (let i = 0; i < length; i++) stars += '*'
    result = result.replace(item, stars)
  }
  return result
})
</script>

<style scoped lang="scss">
.super-chat {
  width: calc(100% - 2rem);
  position: relative;
  display: flex;
  flex-direction: column;
  margin: .4rem 1rem;
  background: var(--z-red-color);
  color: var(--z-light-color);
  font-weight: bold;

  .header {
    display: flex;
    align-items: center;
    padding: 1rem 2rem 1rem 2rem;
    background-color: rgba(0, 0, 0, .2);

    * {
      flex-shrink: 0;
    }

    .image {
      position: relative;
      width: 3rem;
      height: 3rem;
      margin-right: .8rem;

      .avatar {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }

      .mask {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
      }
    }

    .name {
      margin: 0 .4rem;
      font-size: 1.2rem;
    }

    .fee {
      font-size: 1.6rem;
    }
  }

  .content {
    padding: .8rem 2rem 1rem 2rem;
    font-size: 1.1rem;
    word-break: break-all;
    line-break: anywhere;
  }

  .mask {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
  }
}
</style>